package com.evan.review.architecture.mvvm.model;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

/**
 * 笔记数据访问对象
 * MVVM架构中的Model层的一部分，用于数据库操作
 */
@Dao
public interface NoteDao {
    
    /**
     * 插入笔记
     */
    @Insert
    void insert(Note note);
    
    /**
     * 更新笔记
     */
    @Update
    void update(Note note);
    
    /**
     * 删除笔记
     */
    @Delete
    void delete(Note note);
    
    /**
     * 删除所有笔记
     */
    @Query("DELETE FROM notes")
    void deleteAllNotes();
    
    /**
     * 获取所有笔记，按优先级降序排序
     * 使用LiveData，当数据变化时会自动通知观察者
     */
    @Query("SELECT * FROM notes WHERE isArchived = 0 ORDER BY priority DESC")
    LiveData<List<Note>> getAllNotes();
    
    /**
     * 获取所有已归档的笔记
     */
    @Query("SELECT * FROM notes WHERE isArchived = 1 ORDER BY updatedAt DESC")
    LiveData<List<Note>> getArchivedNotes();
    
    /**
     * 根据类别获取笔记
     */
    @Query("SELECT * FROM notes WHERE category = :category AND isArchived = 0 ORDER BY priority DESC")
    LiveData<List<Note>> getNotesByCategory(String category);
    
    /**
     * 搜索笔记
     */
    @Query("SELECT * FROM notes WHERE (title LIKE '%' || :searchQuery || '%' OR " +
            "content LIKE '%' || :searchQuery || '%') AND isArchived = 0")
    LiveData<List<Note>> searchNotes(String searchQuery);
    
    /**
     * 获取高优先级笔记（优先级4-5）
     */
    @Query("SELECT * FROM notes WHERE priority >= 4 AND isArchived = 0 ORDER BY priority DESC")
    LiveData<List<Note>> getHighPriorityNotes();
} 